#include "TcpServer.h"
#include <iostream>
using std::cout;
using std::endl;

//由用户指定对三个事件的处理方式

//新的连接建立
void OnNewConnection(const TcpConnectionPtr & con)
{
    cout << con->toString() << " has connected! " << endl;
}


//客户端发送数据
void OnMessage(const TcpConnectionPtr & con)
{
    string msg = con->receive();
    cout << ">>recv msg from client: " << msg << endl;

    //处理接收到的数据
    /* msg = "msg:" + msg; */

    //处理后的数据发回客户端
    con->send(msg);
}


//连接断开
void OnClose(const TcpConnectionPtr & con)
{
    cout << con->toString() << " has closed! " << endl;
}


void test0(){
    TcpServer server("127.0.0.1",8888);
    server.setAllCallback(OnNewConnection,
                          OnMessage,
                          OnClose);
    server.start();
}

int main(void){
    test0();
    return 0;
}

